<?php

namespace App\Http\Controllers\Admin;

use App\Http\Requests\CreateGoodsContentRequest;
use App\Http\Requests\UpdateGoodsContentRequest;
use App\Repositories\GoodsContentRepository;
use App\Http\Controllers\AppBaseController;
use Illuminate\Http\Request;
use Flash;
use Prettus\Repository\Criteria\RequestCriteria;
use Response;

class GoodsContentController extends AppBaseController
{
    /** @var  GoodsContentRepository */
    private $goodsContentRepository;

    public function __construct(GoodsContentRepository $goodsContentRepo)
    {
        $this->goodsContentRepository = $goodsContentRepo;
    }

    /**
     * Display a listing of the GoodsContent.
     *
     * @param Request $request
     * @return Response
     */
    public function index(Request $request)
    {
        $this->goodsContentRepository->pushCriteria(new RequestCriteria($request));
        $goodsContents = $this->goodsContentRepository->paginate(10);

        return view('goods_contents.index')
            ->with('goodsContents', $goodsContents);
    }

    /**
     * Show the form for creating a new GoodsContent.
     *
     * @return Response
     */
    public function create()
    {
        return view('goods_contents.create');
    }

    /**
     * Store a newly created GoodsContent in storage.
     *
     * @param CreateGoodsContentRequest $request
     *
     * @return Response
     */
    public function store(CreateGoodsContentRequest $request)
    {
        $input = $request->all();

        $goodsContent = $this->goodsContentRepository->create($input);

        Flash::success('Goods Content saved successfully.');

        return redirect(route('goodsContents.index'));
    }

    /**
     * Display the specified GoodsContent.
     *
     * @param  int $id
     *
     * @return Response
     */
    public function show($id)
    {
        $goodsContent = $this->goodsContentRepository->findWithoutFail($id);

        if (empty($goodsContent)) {
            Flash::error('Goods Content not found');

            return redirect(route('goodsContents.index'));
        }

        return view('goods_contents.show')->with('goodsContent', $goodsContent);
    }

    /**
     * Show the form for editing the specified GoodsContent.
     *
     * @param  int $id
     *
     * @return Response
     */
    public function edit($id)
    {
        $goodsContent = $this->goodsContentRepository->findWithoutFail($id);

        if (empty($goodsContent)) {
            Flash::error('Goods Content not found');

            return redirect(route('goodsContents.index'));
        }

        return view('goods_contents.edit')->with('goodsContent', $goodsContent);
    }

    /**
     * Update the specified GoodsContent in storage.
     *
     * @param  int              $id
     * @param UpdateGoodsContentRequest $request
     *
     * @return Response
     */
    public function update($id, UpdateGoodsContentRequest $request)
    {
        $goodsContent = $this->goodsContentRepository->findWithoutFail($id);

        if (empty($goodsContent)) {
            Flash::error('Goods Content not found');

            return redirect(route('goodsContents.index'));
        }

        $goodsContent = $this->goodsContentRepository->update($request->all(), $id);

        Flash::success('Goods Content updated successfully.');

        return redirect(route('goodsContents.index'));
    }

    /**
     * Remove the specified GoodsContent from storage.
     *
     * @param  int $id
     *
     * @return Response
     */
    public function destroy($id)
    {
        $goodsContent = $this->goodsContentRepository->findWithoutFail($id);

        if (empty($goodsContent)) {
            Flash::error('Goods Content not found');

            return redirect(route('goodsContents.index'));
        }

        $this->goodsContentRepository->delete($id);

        Flash::success('Goods Content deleted successfully.');

        return redirect(route('goodsContents.index'));
    }
}
